<template>
  <el-menu
    style="width: 200px; min-height: calc(100vh - 50px)"
    :default-active="path"
    router
    :default-openeds="[`1`]"
    class="el-menu-vertical-demo"
  >
    <el-sub-menu index="1">
      <template #title>系统管理</template>
      <el-menu-item index="/consumer">用户管理</el-menu-item>
    </el-sub-menu>
    <el-menu-item index="/book">书籍管理</el-menu-item>
    <el-menu-item index="/news">新闻管理</el-menu-item>
  </el-menu>
</template>

<script>
import {
  Location,
  Menu as IconMenu,
  Document,
  Setting,
} from "@element-plus/icons-vue";
export default {
  name: "Aside",
  data() {
    return {
      // 设置默认的高亮菜单
      path: this.$route.path,
      consumer: {},
    };
  },
  components: {
    Location,
    IconMenu,
    Document,
    Setting,
  },
  create() {
    // 获取缓存信息，昵称信息赋值给新闻的编写者
    let consumerStr = sessionStorage.getItem("consumer") || "{}";
    let consumer = JSON.parse(consumerStr);

    // 请求服务端，确认当前登录用户的 合法信息
    request.get("/consumer/" + this.consumer.id).then((response) => {
      if (response.result === "SUCCESS") {
        this.consumer = response.data;
      }
    });
  },
};
</script>

<style lang="scss" scoped></style>
